const myexpress=require("express");
const path = require("path");
const logger = require('morgan');
const bodyParser = require('body-parser'); //获取post提交的数据
const userRouter = require('./router/userRouer');
const commodityRouter=require("./router/commodityRouter")
const systemsetRouter=require("./router/systemsetRouter")
const shujuku=require('./router/shujuku')
const app=myexpress();

app.all("*",function(req,res,next){
    //设置允许跨域的域名，*代表允许任意域名跨域
    res.header("Access-Control-Allow-Origin","*");
    //允许的header类型
    res.header("Access-Control-Allow-Headers","content-type");
    //跨域允许的请求方式
    res.header("Access-Control-Allow-Methods","DELETE,PUT,POST,GET,OPTIONS");
    if (req.method.toLowerCase() == 'options')
        res.send(200);  //让options尝试请求快速结束
    else
        next();
})

// 定义日志和输出级别
app.use(logger('dev'));

// 定义数据解析器
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.use(userRouter);
//商品设置
app.use(commodityRouter)
//系统设置
app.use(systemsetRouter);

app.use(myexpress.static(path.join(__dirname,"public"),{index:"login.html"}));
//登录
app.post("/Login",(req,res)=>{
    let name=req.body.username;
    let pwd=req.body.password;
    let sql="SELECT * FROM users WHERE userName = ? AND Pwd=? ";
    shujuku.query(sql,[name,pwd],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            if(data.length>0)
            {
                res.send({code:200,data});
            }else{
                res.send("用户名或者密码出错");
            }
        }
    })
})
//注册
app.post("/Reg",(req,res)=>{
    let name=req.body.username;
    let pwd=req.body.password;
    let sql="INSERT INTO users(userName,Pwd,Juri,Del) VALUE (?,?,4,1)";
    shujuku.query(sql,[name,pwd],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code: 200, data});

        }
    })
})
//获取当前账号权限
app.post("/getjuri",(req,res)=>{
    console.log(req.body);
    let Juri="%"+req.body.juri+"%";
    let sql="SELECT * FROM jruirouter WHERE Jrui LIKE ? ";
    shujuku.query(sql,[Juri],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            if(data.length>0)
            {
                res.send({code:200,data});
            }
        }
    })
})
//修改当前账号密码
app.post("/resuser",(req,res)=>{
    console.log(req.body);
    let Id=req.body.Id;
    let pwd=req.body.Pwd;
    let sql="UPDATE users SET Pwd=? WHERE Id=?";
    shujuku.query(sql,[pwd,Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,data});

        }
    })
})



//权限管理获取数据
app.post("/juri/get",(req,res)=>{
    let sql="SELECT * FROM users JOIN juriguanlian ON  users.Juri=juriguanlian.IdJuri WHERE users.Del=1 ORDER BY users.Id ASC";
    shujuku.query(sql,[],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,data});
        }
    })
})
//权限管理获取权限数据
app.post("/juri/getjuri",(req,res)=>{
    let sql="SELECT * FROM juriguanlian";
    shujuku.query(sql,[],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,data});
        }
    })
})
//权限管理修改权限数据
app.post("/juri/revisejuri",(req,res)=>{
    let sql="UPDATE users SET Juri=? WHERE Id=?";
    shujuku.query(sql,[req.body.juri,req.body.Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200});
        }
    })
})
//权限管理删除用户数据
app.post("/juri/deljuri",(req,res)=>{
    let sql="UPDATE users SET Del=2 WHERE Id=?";
    shujuku.query(sql,[req.body.Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200});
        }
    })
})
//权限查询
app.post("/juri/queryjuri",(req,res)=>{
    let neirong="%"+req.body.neirong+"%"
    let sql="SELECT * FROM users JOIN juriguanlian ON  users.Juri=juriguanlian.IdJuri WHERE users.Del=1 and users.userName LIKE ?  ORDER BY users.Id ASC";
    shujuku.query(sql,[neirong],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,data});
        }
    })
})


// 客户管理
app.get("/CustomerInfoList",(req,res)=>{//客户资料
    let sql = "select * from customerinfo"
    shujuku.query(sql,[],function(err,data){
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,msg:'获取成功',data:data});
        }
    })
})
app.post("/addEditCustomerInfo",(req,res)=>{//客户资料添加修改
    let fun = req.body.fun;
    let id = req.body.id;
    let memberCardNum = req.body.memberCardNum;
    let memberName = req.body.memberName;
    let memberType = req.body.memberType;
    let sex = req.body.sex;
    let birthday = req.body.birthday;
    let totalIntegral = req.body.totalIntegral;
    let totalMonetary = req.body.totalMonetary;
    let phone = req.body.phone;
    let idNum = req.body.idNum;
    let openCardStore = req.body.openCardStore;
    let openCardDate = req.body.openCardDate;
    let addSql = "INSERT INTO customerinfo (memberCardNum,memberName,memberType,sex,birthday,totalIntegral,totalMonetary,phone,idNum,openCardStore,openCardDate) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
    let editSql = "update customerinfo set memberCardNum = ?,memberName = ?,memberType = ?,sex = ?,birthday = ?,totalIntegral = ?,totalMonetary = ?,phone = ?,idNum = ?,openCardStore = ?,openCardDate = ? where id = ?";
    if(fun == 0){
        shujuku.query(addSql,[memberCardNum,memberName,memberType,sex,birthday,totalIntegral,totalMonetary,phone,idNum,openCardStore,openCardDate],function(err,data){
            if(err){
                console.log(err);
                res.send("数据库出错，请联系管理员");
            }else{
                if(data.affectedRows>0){
                    res.send({code:200,msg:"添加成功"});
                }else{
                    res.send({code:201,msg:"添加失败"});
                }
            }
        })
    }else if(fun == 1){
        shujuku.query(editSql,[memberCardNum,memberName,memberType,sex,birthday,totalIntegral,totalMonetary,phone,idNum,openCardStore,openCardDate,id],function(err,data){
            if(err){
                console.log(err);
                res.send("数据库出错，请联系管理员");
            }else{
                if(data.affectedRows>0){
                    res.send({code:200,msg:"修改成功"});
                }else{
                    res.send({code:201,msg:"修改失败"});
                }
            }
        })
    }  
})
app.post("/delCustomerInfo",(req,res)=>{//删除
    let id = req.body.id;
    console.log(id);
    let sql = "delete from customerinfo where id = ?";
    shujuku.query(sql,[id],function (err,data) {
        if(err){
            res.send({code:500,message:"数据库出错"});
        }else{
            if(data.affectedRows>0){
                res.send({code:200,msg:"删除成功"});
            }else{
                res.send({code:201,msg:"删除失败"});
            }
        }
    })
})
app.post("/upgrade",(req,res)=>{//会员升级
    let id = req.body.id;
    let memberType = req.body.memberType;
    let totalIntegral = req.body.totalIntegral;
    let sql = "update customerinfo set memberType = ?, totalIntegral = ? where id = ?";
    shujuku.query(sql,[memberType,totalIntegral,id],function (err,data) {
        if(err){
            res.send({code:500,message:"数据库出错"});
        }else{
            if(data.affectedRows>0){
                res.send({code:200,msg:"升级成功"});
            }else{
                res.send({code:201,msg:"升级失败"});
            }
        }
    })
})
app.post("/searchCustomerInfo",(req,res)=>{//查询
    let cardNum = '%'+req.body.cardNum+'%';
    let sql = "select * from customerinfo where memberCardNum like ?";
    shujuku.query(sql,[cardNum],function (err,data) {
        if(err){
            res.send({code:500,message:"数据库出错"});
        }else{
            res.send({code:200,msg:"查询成功",data:data});
        }
    })
})
//会员卡管理
app.get("/memberCardList",(req,res)=>{//会员卡管理
    let sql = "select * from membercardmanage"
    shujuku.query(sql,[],function(err,data){
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,msg:'获取成功',data:data});
        }
    })
})
app.post("/addEditMemberCard",(req,res)=>{//会员卡添加修改
    let fun = req.body.fun;
    let id = req.body.id;
    let memberType = req.body.memberType;
    let isIntegral = req.body.isIntegral;
    let upIntegral = req.body.upIntegral;
    let addSql = "INSERT INTO membercardmanage (memberType,upgradeQuota,isIntegral) VALUES (?,?,?)";
    let editSql = "update membercardmanage set memberType=?,upgradeQuota=?,isIntegral=? where id = ?";
    if(fun == 0){
        shujuku.query(addSql,[memberType,upIntegral,isIntegral],function(err,data){
            if(err){
                console.log(err);
                res.send("数据库出错，请联系管理员");
            }else{
                if(data.affectedRows>0){
                    res.send({code:200,msg:"添加成功"});
                }else{
                    res.send({code:201,msg:"添加失败"});
                }
            }
        })
    }else if(fun == 1){
        shujuku.query(editSql,[memberType,upIntegral,isIntegral,id],function(err,data){
            if(err){
                console.log(err);
                res.send("数据库出错，请联系管理员");
            }else{
                if(data.affectedRows>0){
                    res.send({code:200,msg:"修改成功"});
                }else{
                    res.send({code:201,msg:"修改失败"});
                }
            }
        })
    }
})
app.post("/delMemberCard",(req,res)=>{//删除
    let id = req.body.id;
    console.log(id);
    let sql = "delete from membercardmanage where id = ?";
    shujuku.query(sql,[id],function (err,data) {
        if(err){
            res.send({code:500,message:"数据库出错"});
        }else{
            if(data.affectedRows>0){
                res.send({code:200,msg:"删除成功"});
            }else{
                res.send({code:201,msg:"删除失败"});
            }
        }
    })
})
// 客户折扣
app.get("/customerDiscountList",(req,res)=>{//会员卡管理
    let sql = "select * from customerdiscount"
    shujuku.query(sql,[],function(err,data){
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,msg:'获取成功',data:data});
        }
    })
})
app.post("/addEditCustomerDiscount",(req,res)=>{//折扣添加修改
    let fun = req.body.fun;
    let id = req.body.id;
    let memberType = req.body.memberType;
    let productType = req.body.productType;
    let productClass = req.body.productClass;
    let salesType = req.body.salesType;
    let salesMode = req.body.salesMode;
    let birthdayDiscount = req.body.birthdayDiscount;
    let discount = req.body.discount;
    let addSql = "INSERT INTO customerdiscount (memberType,productType,productClass,salesType,salesMode,birthdayDiscount,discount) VALUES (?,?,?,?,?,?,?)";
    let editSql = "update customerdiscount set memberType=?,productType=?,productClass=?,salesType=?,salesMode=?,birthdayDiscount=?,discount=? where id = ?";
    if(fun == 0){
        shujuku.query(addSql,[memberType,productType,productClass,salesType,salesMode,birthdayDiscount,discount],function(err,data){
            if(err){
                console.log(err);
                res.send("数据库出错，请联系管理员");
            }else{
                if(data.affectedRows>0){
                    res.send({code:200,msg:"添加成功"});
                }else{
                    res.send({code:201,msg:"添加失败"});
                }
            }
        })
    }else if(fun == 1){
        shujuku.query(editSql,[memberType,productType,productClass,salesType,salesMode,birthdayDiscount,discount,id],function(err,data){
            if(err){
                console.log(err);
                res.send("数据库出错，请联系管理员");
            }else{
                if(data.affectedRows>0){
                    res.send({code:200,msg:"修改成功"});
                }else{
                    res.send({code:201,msg:"修改失败"});
                }
            }
        })
    }
})
app.post("/delCustomerDiscount",(req,res)=>{//删除
    let id = req.body.id;
    let sql = "delete from customerdiscount where id = ?";
    shujuku.query(sql,[id],function (err,data) {
        if(err){
            res.send({code:500,message:"数据库出错"});
        }else{
            if(data.affectedRows>0){
                res.send({code:200,msg:"删除成功"});
            }else{
                res.send({code:201,msg:"删除失败"});
            }
        }
    })
})
// 积分规则
app.get("/IntegralRuleList",(req,res)=>{//会员卡管理
    let sql = "select * from integralrule"
    shujuku.query(sql,[],function(err,data){
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,msg:'获取成功',data:data});
        }
    })
})
app.post("/addEditIntegralRule",(req,res)=>{//折扣添加修改
    let fun = req.body.fun;
    let id = req.body.id;
    let productName = req.body.productName;
    let salesMode = req.body.salesMode;
    let priceType = req.body.priceType;
    let productType = req.body.productType;
    let IntegralCoefficient = req.body.IntegralCoefficient;
    let isEnable = req.body.isEnable;
    let addSql = "INSERT INTO integralrule (productName,salesMode,priceType,productType,IntegralCoefficient,isEnable) VALUES (?,?,?,?,?,?)";
    let editSql = "update integralrule set productName=?,salesMode=?,priceType=?,productType=?,IntegralCoefficient=?,isEnable=? where id = ?";
    if(fun == 0){
        shujuku.query(addSql,[productName,salesMode,priceType,productType,IntegralCoefficient,isEnable],function(err,data){
            if(err){
                console.log(err);
                res.send("数据库出错，请联系管理员");
            }else{
                if(data.affectedRows>0){
                    res.send({code:200,msg:"添加成功"});
                }else{
                    res.send({code:201,msg:"添加失败"});
                }
            }
        })
    }else if(fun == 1){
        shujuku.query(editSql,[productName,salesMode,priceType,productType,IntegralCoefficient,isEnable,id],function(err,data){
            if(err){
                console.log(err);
                res.send("数据库出错，请联系管理员");
            }else{
                if(data.affectedRows>0){
                    res.send({code:200,msg:"修改成功"});
                }else{
                    res.send({code:201,msg:"修改失败"});
                }
            }
        })
    }
})
app.post("/delIntegralRule",(req,res)=>{//删除
    let id = req.body.id;
    let sql = "delete from integralrule where id = ?";
    shujuku.query(sql,[id],function (err,data) {
        if(err){
            res.send({code:500,message:"数据库出错"});
        }else{
            if(data.affectedRows>0){
                res.send({code:200,msg:"删除成功"});
            }else{
                res.send({code:201,msg:"删除失败"});
            }
        }
    })
})
app.post("/searchIntegralRule",(req,res)=>{//查询
    console.log(req.body);
    let productType = req.body.productType;
    let priceType = req.body.priceType;
    let salesMode = req.body.salesMode;
    let sql = "select * from integralrule where ";
    let needAdd = false;
    if(productType != ''){
        sql = needAdd?sql + 'and productType = ' + productType + ' ':sql + 'productType = ' + productType + ' ';
        needAdd = true;
    }
    if(priceType != ''){
        sql = needAdd?sql + 'and priceType = ' + priceType + ' ':sql + 'priceType = ' + priceType + ' ';
        needAdd = true;
    }
    if(salesMode != ''){
        sql = needAdd?sql + 'and salesMode = ' + salesMode + ' ':sql + 'salesMode = ' + salesMode + ' ';
        needAdd = true;
    }
    
    shujuku.query(sql,[],function (err,data) {
        if(err){
            console.log(err);
            res.send({code:500,message:"数据库出错"});
        }else{
            res.send({code:200,msg:"查询成功",data:data});
        }
    })
})
// 客户消费查询
app.post("/searchCustomerConsumptione",(req,res)=>{//查询
    console.log(req.body);
    let searchMode = req.body.searchMode;
    let SearchContext = req.body.SearchContext;
    let sql = "select productCode,productName,quantity,tagPrice,discount,paidInAmount,integral,purchaseDate from customerconsumptionrecord where memberCardNum = ?";
    let sql1 = "select productCode,productName,quantity,tagPrice,discount,paidInAmount,integral,purchaseDate from customerconsumptionrecord where phone = ?";
    if(searchMode == 0){
        shujuku.query(sql,[SearchContext],function (err,data) {
            if(err){
                res.send({code:500,message:"数据库出错"});
            }else{
                console.log(data);
                res.send({code:200,msg:"查询成功",data:data});
            }
        })
    }else if (searchMode == 1){
        shujuku.query(sql1,[SearchContext],function (err,data) {
            if(err){
                res.send({code:500,message:"数据库出错"});
            }else{
                res.send({code:200,msg:"查询成功",data:data});
            }
        })
    }
})
// 供应商基础设置
app.get("/supplierList",(req,res)=>{//获取
    let sql = "select * from supplierbasicdata"
    shujuku.query(sql,[],function(err,data){
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,msg:'获取成功',data:data});
        }
    })
})
app.post("/addEditSupplier",(req,res)=>{//添加修改
    let fun = req.body.fun;
    let id = req.body.id;
    let supplierName = req.body.supplierName;
    let supplierCode = req.body.supplierCode;
    let supplierPhone = req.body.supplierPhone;
    let contacts = req.body.contacts;
    let address = req.body.address;
    let email = req.body.email;
    let addSql = "INSERT INTO supplierbasicdata (supplierName,supplierCode,supplierPhone,contacts,address,email) VALUES (?,?,?,?,?,?)";
    let editSql = "update supplierbasicdata set supplierName=?,supplierCode=?,supplierPhone=?,contacts=?,address=?,email=? where id = ?";
    if(fun == 0){
        shujuku.query(addSql,[supplierName,supplierCode,supplierPhone,contacts,address,email],function(err,data){
            if(err){
                console.log(err);
                res.send("数据库出错，请联系管理员");
            }else{
                if(data.affectedRows>0){
                    res.send({code:200,msg:"添加成功"});
                }else{
                    res.send({code:201,msg:"添加失败"});
                }
            }
        })
    }else if(fun == 1){
        shujuku.query(editSql,[supplierName,supplierCode,supplierPhone,contacts,address,email,id],function(err,data){
            if(err){
                console.log(err);
                res.send("数据库出错，请联系管理员");
            }else{
                if(data.affectedRows>0){
                    res.send({code:200,msg:"修改成功"});
                }else{
                    res.send({code:201,msg:"修改失败"});
                }
            }
        })
    }
})
app.post("/delSupplier",(req,res)=>{//删除
    let id = req.body.id;
    let sql = "delete from supplierbasicdata where id = ?";
    shujuku.query(sql,[id],function (err,data) {
        if(err){
            res.send({code:500,message:"数据库出错"});
        }else{
            if(data.affectedRows>0){
                res.send({code:200,msg:"删除成功"});
            }else{
                res.send({code:201,msg:"删除失败"});
            }
        }
    })
})
app.post("/searchSupplier",(req,res)=>{//查询
    let supplierName = '%'+req.body.supplierName+'%';
    let sql = "select * from supplierbasicdata where supplierName like ?";
    shujuku.query(sql,[supplierName],function (err,data) {
        if(err){
            res.send({code:500,message:"数据库出错"});
        }else{
            res.send({code:200,msg:"查询成功",data:data});
        }
    })
})


//固定编码入库显示
app.get("/commoditywarehousing/get",(req,res)=>{
    let sql="SELECT * FROM commoditywarehousing WHERE Del=1";
    shujuku.query(sql,[],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,data});
        }
    })
})
//固定编码入库添加
app.post("/commoditywarehousing/add",(req,res)=>{
    console.log(req.body)
    let Number=req.body.Number;
    let CommodityType=req.body.CommodityType;
    let Supplier=req.body.Supplier;
    let WarehousingStore=req.body.WarehousingStore;
    let Source=req.body.Source;
    let CommodityNum=req.body.CommodityNum;
    let CommodityNmae=req.body.CommodityNmae;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql="INSERT INTO \n" +
        "commoditywarehousing\n" +
        "(Number,CommodityType,Supplier,WarehousingStore,Source,CommodityNum,CommodityNmae,Condit,Weight,Quantity,Cost) \n" +
        "VALUE \n" +
        "(?,?,?,?,?,?,?,?,?,?,?)";
    shujuku.query(sql,[Number,CommodityType,Supplier,WarehousingStore,Source,CommodityNum,CommodityNmae,Condit,Weight,Quantity,Cost],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//固定编码入库修改
app.post("/commoditywarehousing/re",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let CommodityType=req.body.CommodityType;
    let CommodityNum=req.body.CommodityNum;
    let CommodityNmae=req.body.CommodityNmae;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql='UPDATE commoditywarehousing SET CommodityType=?, CommodityNum=?, CommodityNmae=?, Condit=?, weight=?, Quantity=?, Cost=?,State=3 WHERE Id=?';
    shujuku.query(sql,[CommodityType,CommodityNum,CommodityNmae,Condit,Weight,Quantity,Cost,Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//固定编码入库审核通过
app.post("/commoditywarehousing/adopt",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE commoditywarehousing set State=1 WHERE Id=?';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//固定编码入库审核不通过
app.post("/commoditywarehousing/reject",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE commoditywarehousing set State=2 WHERE Id=?';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//固定编码入库删除
app.post("/commoditywarehousing/Del",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE commoditywarehousing set Del=2 WHERE Id=?';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//固定编码入库查询
app.post("/commoditywarehousing/chaxun",(req,res)=>{
    console.log(req.body)
    let Number="%"+req.body.Number+"%";
    let sql='SELECT * FROM commoditywarehousing WHERE Number LIKE ? AND Del=1';
    shujuku.query(sql,[Number],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})


//采购退货显示
app.get("/caigoutuihou/get",(req,res)=>{
    let sql="SELECT * FROM caigoutuihuo WHERE Del=1 AND Dan=1";
    shujuku.query(sql,[],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//采购退货添加
app.post("/caigoutuihou/add",(req,res)=>{
    console.log(req.body)
    let Number=req.body.Number;
    let CommodityType=req.body.CommodityType;
    let Supplier=req.body.Supplier;
    let WarehousingStore=req.body.WarehousingStore;
    let Warehousing=req.body.Warehousing;
    let CommodityNum=req.body.CommodityNum;
    let CommodityName=req.body.CommodityName;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql="INSERT INTO \n" +
        "caigoutuihuo\n" +
        "(Number,CommodityType,Supplier,WarehousingStore,Warehousing,CommodityNum,CommodityName,Condit,Weight,Quantity,Cost,Dan) \n" +
        "VALUE \n" +
        "(?,?,?,?,?,?,?,?,?,?,?,1)";
    shujuku.query(sql,[Number,CommodityType,Supplier,WarehousingStore,Warehousing,CommodityNum,CommodityName,Condit,Weight,Quantity,Cost],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//采购退货修改
app.post("/caigoutuihou/re",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let CommodityNum=req.body.CommodityNum;
    let CommodityName=req.body.CommodityName;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql='UPDATE caigoutuihuo SET CommodityNum=?, CommodityName=?, Condit=?, weight=?, Quantity=?, Cost=?,State=3 WHERE Id=? AND Del=1 AND Dan=1';
    shujuku.query(sql,[CommodityNum,CommodityName,Condit,Weight,Quantity,Cost,Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//采购退货审核通过
app.post("/caigoutuihou/tongguo",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE caigoutuihuo set State=1 WHERE Id=? and Del=1 AND Dan=1';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//采购退货审核不通过
app.post("/caigoutuihou/butongguo",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE caigoutuihuo set State=2 WHERE Id=? and Del=1 AND Dan=1';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//采购退货删除
app.post("/caigoutuihou/Del",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE caigoutuihuo set Del=2 WHERE Id=? and Del=1 AND Dan=1';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//采购退货查询
app.post("/caigoutuihou/chaxun",(req,res)=>{
    console.log(req.body)
    let Number="%"+req.body.Number+"%";
    let sql='SELECT * FROM caigoutuihuo WHERE Number LIKE ? and Del=1 AND Dan=1';
    shujuku.query(sql,[Number],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})


//商品拆料显示
app.get("/GoodsDownMaterial/getMessage",(req,res)=>{
    let sql="SELECT * FROM caigoutuihuo WHERE Del=1 AND Dan=2";
    shujuku.query(sql,[],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,data});
        }
    })
})
//商品拆料添加
app.post("/GoodsDownMaterial/addMessage",(req,res)=>{
    console.log(req.body)
    let Number=req.body.Number;
    let CommodityType=req.body.CommodityType;
    let WarehousingStore=req.body.WarehousingStore;
    let CommodityNum=req.body.CommodityNum;
    let CommodityName=req.body.CommodityName;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql="INSERT INTO \n" +
        "caigoutuihuo\n" +
        "(Number,CommodityType,WarehousingStore,CommodityNum,CommodityName,Condit,Weight,Quantity,Cost,Dan) \n" +
        "VALUE \n" +
        "(?,?,?,?,?,?,?,?,?,2)";
    shujuku.query(sql,[Number,CommodityType,WarehousingStore,CommodityNum,CommodityName,Condit,Weight,Quantity,Cost],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//商品拆料修改
app.post("/GoodsDownMaterial/changeMessage",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let CommodityNum=req.body.CommodityNum;
    let CommodityName=req.body.CommodityName;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql='UPDATE caigoutuihuo SET CommodityNum=?, CommodityName=?, Condit=?, weight=?, Quantity=?, Cost=? WHERE Id=? and Del=1 AND Dan=2';
    shujuku.query(sql,[CommodityNum,CommodityName,Condit,Weight,Quantity,Cost,Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//商品拆料审核通过
app.post("/GoodsDownMaterial/passAudit",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE caigoutuihuo set State=1 WHERE Id=? and Del=1 AND Dan=2';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//商品拆料审核不通过
app.post("/GoodsDownMaterial/auditFailed",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE caigoutuihuo set State=2 WHERE Id=? and Del=1 AND Dan=2';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//商品拆料删除
app.post("/GoodsDownMaterial/delMessage",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE caigoutuihuo set Del=2 WHERE Id=? and Del=1 AND Dan=2';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//商品拆料查询
app.post("/GoodsDownMaterial/findMessage",(req,res)=>{
    console.log(req.body)
    let Number="%"+req.body.Number+"%";
    let sql='SELECT * FROM caigoutuihuo WHERE Number LIKE ?  and Del=1 AND Dan=2';
    shujuku.query(sql,[Number],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})

//库存统计显示
app.get("/kucuntongji/xianshi",(req,res)=>{
    let sql="SELECT * FROM kucuntongji ";
    shujuku.query(sql,[],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//库存统计查询
app.post("/kucuntongji/chaxun",(req,res)=>{
    console.log(req.body)
    let WarehousingStore="%"+req.body.WarehousingStore+"%";
    let CommodityNum="%"+req.body.CommodityNum+"%";
    let sql='SELECT * FROM kucuntongji WHERE WarehousingStore LIKE ? AND CommodityNum LIKE ?';
    shujuku.query(sql,[WarehousingStore,CommodityNum],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})

//门店退货显示
app.get("/StoreSeturn/getMessage",(req,res)=>{
    let sql="SELECT * FROM chukuruku WHERE Del=1 AND Dan=1";
    shujuku.query(sql,[],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//门店退货添加
app.post("/StoreSeturn/addMessage",(req,res)=>{
    console.log(req.body)
    let Number=req.body.Number;
    let WarehousingStore=req.body.WarehousingStore;
    let Warehousing=req.body.Warehousing;
    let PutStore=req.body.PutStore;
    let Puting=req.body.Puting;
    let CommodityType=req.body.CommodityType;
    let CommodityNum=req.body.CommodityNum;
    let CommodityName=req.body.CommodityName;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql="INSERT INTO \n" +
        "chukuruku\n" +
        "(Number,WarehousingStore,Warehousing,PutStore,Puting,CommodityType,CommodityNum,CommodityName,Condit,Weight,Quantity,Cost,Dan) \n" +
        "VALUE \n" +
        "(?,?,?,?,?,?,?,?,?,?,?,?,1)";
    shujuku.query(sql,[Number,WarehousingStore,Warehousing,PutStore,Puting,CommodityType,CommodityNum,CommodityName,Condit,Weight,Quantity,Cost],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//门店退货修改
app.post("/StoreSeturn/changeMessage",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let CommodityNum=req.body.CommodityNum;
    let CommodityName=req.body.CommodityName;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql='UPDATE chukuruku SET CommodityNum=?, CommodityName=?, Condit=?, weight=?, Quantity=?, Cost=? WHERE Id=? and Del=1 AND Dan=1';
    shujuku.query(sql,[CommodityNum,CommodityName,Condit,Weight,Quantity,Cost,Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//门店退货审核通过
app.post("/StoreSeturn/passAudit",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE chukuruku set State=1 WHERE Id=? and Del=1 AND Dan=1';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//门店退货审核不通过
app.post("/StoreSeturn/auditFailed",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE chukuruku set State=2 WHERE Id=? and Del=1 AND Dan=1';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//门店退货删除
app.post("/StoreSeturn/delMessage",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE chukuruku set Del=2 WHERE Id=? and Del=1 AND Dan=1';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//门店退货查询
app.post("/StoreSeturn/findMessage",(req,res)=>{
    console.log(req.body)
    let Number="%"+req.body.Number+"%";
    let sql='SELECT * FROM chukuruku WHERE Number LIKE ?  and Del=1 AND Dan=1';
    shujuku.query(sql,[Number],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})

//配货出库显示
app.get("/peihuochuku/get",(req,res)=>{
    let sql="SELECT * FROM chukuruku WHERE Del=1 AND Dan=2";
    shujuku.query(sql,[],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//配货出库添加
app.post("/peihuochuku/add",(req,res)=>{
    console.log(req.body)
    let Number=req.body.Number;
    let WarehousingStore=req.body.WarehousingStore;
    let Warehousing=req.body.Warehousing;
    let PutStore=req.body.PutStore;
    let Puting=req.body.Puting;
    let CommodityType=req.body.CommodityType;
    let CommodityNum=req.body.CommodityNum;
    let CommodityName=req.body.CommodityName;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql="INSERT INTO \n" +
        "chukuruku\n" +
        "(Number,WarehousingStore,Warehousing,PutStore,Puting,CommodityType,CommodityNum,CommodityName,Condit,Weight,Quantity,Cost,Dan) \n" +
        "VALUE \n" +
        "(?,?,?,?,?,?,?,?,?,?,?,?,2)";
    shujuku.query(sql,[Number,WarehousingStore,Warehousing,PutStore,Puting,CommodityType,CommodityNum,CommodityName,Condit,Weight,Quantity,Cost],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//配货出库修改
app.post("/peihuochuku/re",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let CommodityNum=req.body.CommodityNum;
    let CommodityName=req.body.CommodityName;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql='UPDATE chukuruku SET CommodityNum=?, CommodityName=?, Condit=?, weight=?, Quantity=?, Cost=?,State=3 WHERE Id=? and Del=1 AND Dan=2';
    shujuku.query(sql,[CommodityNum,CommodityName,Condit,Weight,Quantity,Cost,Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//配货出库审核通过
app.post("/peihuochuku/adopt",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE chukuruku set State=1 WHERE Id=? and Del=1 AND Dan=2';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//配货出库审核不通过
app.post("/peihuochuku/reject",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE chukuruku set State=2 WHERE Id=? and Del=1 AND Dan=2';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//配货出库删除
app.post("/peihuochuku/Del",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE chukuruku set Del=2 WHERE Id=? and Del=1 AND Dan=2';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//配货出库查询
app.post("/peihuochuku/chaxun",(req,res)=>{
    console.log(req.body)
    let Number="%"+req.body.Number+"%";
    let sql='SELECT * FROM chukuruku WHERE Number LIKE ?  and Del=1 AND Dan=2';
    shujuku.query(sql,[Number],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,data});
        }
    })
})

//门店调拨显示
app.get("/StoresAllocating/getMessage",(req,res)=>{
    let sql="SELECT * FROM chukuruku WHERE Del=1 AND Dan=3";
    shujuku.query(sql,[],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//门店调拨添加
app.post("/StoresAllocating/addMessage",(req,res)=>{
    console.log(req.body)
    let Number=req.body.Number;
    let WarehousingStore=req.body.WarehousingStore;
    let Warehousing=req.body.Warehousing;
    let PutStore=req.body.PutStore;
    let Puting=req.body.Puting;
    let CommodityType=req.body.CommodityType;
    let CommodityNum=req.body.CommodityNum;
    let CommodityName=req.body.CommodityName;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql="INSERT INTO \n" +
        "chukuruku\n" +
        "(Number,WarehousingStore,Warehousing,PutStore,Puting,CommodityType,CommodityNum,CommodityName,Condit,Weight,Quantity,Cost,Dan) \n" +
        "VALUE \n" +
        "(?,?,?,?,?,?,?,?,?,?,?,?,3)";
    shujuku.query(sql,[Number,WarehousingStore,Warehousing,PutStore,Puting,CommodityType,CommodityNum,CommodityName,Condit,Weight,Quantity,Cost],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//门店调拨修改
app.post("/StoresAllocating/changeMessage",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let CommodityNum=req.body.CommodityNum;
    let CommodityName=req.body.CommodityName;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql='UPDATE chukuruku SET CommodityNum=?, CommodityName=?, Condit=?, weight=?, Quantity=?, Cost=? WHERE Id=? and Del=1 AND Dan=3';
    shujuku.query(sql,[CommodityNum,CommodityName,Condit,Weight,Quantity,Cost,Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//门店调拨审核通过
app.post("/StoresAllocating/passAudit",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE chukuruku set State=1 WHERE Id=? and Del=1 AND Dan=3';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//门店调拨审核不通过
app.post("/StoresAllocating/auditFailed",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE chukuruku set State=2 WHERE Id=? and Del=1 AND Dan=3';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//门店调拨删除
app.post("/StoresAllocating/delMessage",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE chukuruku set Del=2 WHERE Id=? and Del=1 AND Dan=3';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//门店调拨查询
app.post("/StoresAllocating/findMessage",(req,res)=>{
    console.log(req.body)
    let Number="%"+req.body.Number+"%";
    let sql='SELECT * FROM chukuruku WHERE Number LIKE ?  and Del=1 AND Dan=3';
    shujuku.query(sql,[Number],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})

//商品入库显示
app.get("/GoodsWarehousing/getMessage",(req,res)=>{
    let sql="SELECT * FROM commoditywarehousing  WHERE DEL=1 ";
    shujuku.query(sql,[],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            res.send({code:200,data});
        }
    })
})
//商品入库添加
app.post("/GoodsWarehousing/addMessage",(req,res)=>{
    console.log(req.body)
    let Number=req.body.Number;
    let CommodityType=req.body.CommodityType;
    let Supplier=req.body.Supplier;
    let WarehousingStore=req.body.WarehousingStore;
    let Source=req.body.Source;
    let CommodityNum=req.body.CommodityNum;
    let CommodityNmae=req.body.CommodityNmae;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql="INSERT INTO \n" +
        "commoditywarehousing\n" +
        "(Number,CommodityType,Supplier,WarehousingStore,Source,CommodityNum,CommodityNmae,Condit,Weight,Quantity,Cost) \n" +
        "VALUE \n" +
        "(?,?,?,?,?,?,?,?,?,?,?)";
    shujuku.query(sql,[Number,CommodityType,Supplier,WarehousingStore,Source,CommodityNum,CommodityNmae,Condit,Weight,Quantity,Cost],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//商品入库修改
app.post("/GoodsWarehousing/changeMessage",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let CommodityNum=req.body.CommodityNum;
    let CommodityNmae=req.body.CommodityNmae;
    let Condit=req.body.Condit;
    let Weight=req.body.Weight;
    let Quantity=req.body.Quantity;
    let Cost=req.body.Cost;
    let sql='UPDATE commoditywarehousing SET CommodityNum=?, CommodityNmae=?, Condit=?, weight=?, Quantity=?, Cost=? WHERE Id=?';
    shujuku.query(sql,[CommodityNum,CommodityNmae,Condit,Weight,Quantity,Cost,Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//商品入库审核通过
app.post("/GoodsWarehousing/passAudit",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE commoditywarehousing set State=1 WHERE Id=?';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//商品入库审核不通过
app.post("/GoodsWarehousing/auditFailed",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE commoditywarehousing set State=2 WHERE Id=?';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//商品入库删除
app.post("/GoodsWarehousing/delMessage",(req,res)=>{
    console.log(req.body)
    let Id=req.body.Id;
    let sql='UPDATE commoditywarehousing set Del=2 WHERE Id=?';
    shujuku.query(sql,[Id],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})
//商品入库查询
app.post("/GoodsWarehousing/findMessage",(req,res)=>{
    console.log(req.body)
    let Number="%"+req.body.Number+"%";
    let sql='SELECT * FROM commoditywarehousing WHERE Number LIKE ? and DEL=1';
    shujuku.query(sql,[Number],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})

//员工显示
app.get('/displayList',function(req,res){
    let sql=`SELECT * FROM staffset`
    shujuku.query(sql,[],(err,data)=>{
        if(err){
            console.log(err);
            res.send({code:500,message:"数据库出错请联系管理员"})
        }else{
            res.send({code:200,data:data})
        }
    })
 })
 //员工增加和修改
 app.post('/staffTianjia',(req,res)=>{
    console.log(req.body)
    console.log(res)
    let fun=req.body.fun;
    let id=req.body.id
    let namess=req.body.namess
    let userBranch=req.body.userBranch
    let userId=req.body.userId
    let userName=req.body.userName
    let nameId=req.body.nameId
    let role=req.body.role
    let identityId=req.body.identityId
    let phone=req.body.phone
    let addsql=`INSERT INTO staffset (namess,userBranch,userId,userName,nameId,role,identityId,phone) VALUES (?,?,?,?,?,?,?,?)`
    let editsql=`UPDATE staffset SET namess=? ,userBranch=?,userId=?,userName=?,nameId=?,role=?,identityId=?,phone=? where id=?`
    if(fun==0){
        shujuku.query(addsql,[namess,userBranch,userId,userName,nameId,role,identityId,phone],function(err,data){
            if(err){
                console.log(err)
                res.send("数据库出错请联系管理员")
            }else{
                if(data.affectedRows>0){
                    res.send({code:200,msg:"添加成功"})
                }else{
                    res.send({code:201,msg:"添加失败"})
                }
            }
        })
    }else if(fun==1){
        shujuku.query(editsql,[namess,userBranch,userId,userName,nameId,role,identityId,phone,id],function(err,data){
            if(err){
                console.log(err)
                res.send("数据库出错请联系管理员")
            }else{
                if(data.affectedRows>0){
                    res.send({code:200,msg:"修改成功"})
                }else{
                    res.send({code:201,msg:"修改失败"})
                }
            }
        })
    }
})
//员工删除
app.post("/delStaffInfo",(req,res)=>{//删除
    let id = req.body.id;
    console.log(id);
    let sql = "delete from staffset where id = ?";
    shujuku.query(sql,[id],function (err,data) {
        if(err){
            res.send({code:500,message:"数据库出错"});
        }else{
            if(data.affectedRows>0){
                res.send({code:200,msg:"删除成功"});
            }else{
                res.send({code:201,msg:"删除失败"});
            }
        }
    })
})
//员工查询
app.post("/staffset/chaxun",(req,res)=>{
    console.log(req.body)
    let namess=req.body.namess;
    let sql='SELECT * FROM staffset WHERE namess LIKE ?';
    shujuku.query(sql,[namess],function (err,data) {
        if(err){
            console.log(err);
            res.send("数据库出错，请联系管理员");
        }else{
            console.log(data)
            res.send({code:200,data});
        }
    })
})






app.listen(8888,function () {
    console.log("服务已启动");
})